package com.yebxxx.server.controller;

import com.yebxxx.server.pojo.RespBean;
import com.yebxxx.server.pojo.Teacher;
import com.yebxxx.server.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnel/train/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "教师列表")
    @GetMapping("/")
    public List<Teacher> teacherList(){
      return  teacherService.list();
    }

    @ApiOperation(value = "修改教师")
    @PutMapping("/{id}")
    public RespBean updateTeacher(Teacher teacher){
         if(teacherService.updateById(teacher)){
             return  RespBean.success("修改成功");
         }
         return  RespBean.error("修改失败");
    }
    @ApiOperation(value = "添加教师")
    @PostMapping("/")
    public RespBean addTeacher(@RequestBody Teacher teacher){
        if(teacherService.save(teacher)){
            return  RespBean.success("添加成功");
        }
        return  RespBean.error("添加失败");
    }

    @ApiOperation(value = "删除教师")
    @DeleteMapping("/{id}")
    public RespBean deleteTeacher(Integer id){
        if(teacherService.removeById(id)){
            return  RespBean.success("删除成功");
        }
        return  RespBean.error("删除失败");
    }
}
